package charazay.tool.managers.site;

import java.io.IOException;
import java.util.HashMap;

import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import charazay.tool.cobjects.Team;
import charazay.tool.managers.XML.TeamContentHandler;

public class TeamSiteManager extends GenericSiteManager {
	int teamID = 0;
	
	public TeamSiteManager(int teamID) {
		this.teamID = teamID;
	}

	
	public Team request(String username, String password) {
		String request_url = buildURL(username, password, String.valueOf(TEAM_INFORMATION), String.valueOf(teamID) );
		XMLReader saxReader = null;
		Team team = null;
		
		try {
			saxReader = XMLReaderFactory.createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser");
			saxReader.setContentHandler(new TeamContentHandler());
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			saxReader.parse(request_url);
			team = ((TeamContentHandler)saxReader.getContentHandler()).getTeam();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return team;
	}

}
